package com.learn.netty.server.service.handler;

import com.iverson.example9.protobuf.MyDataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class TestServerHandler extends SimpleChannelInboundHandler<MyDataInfo.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MyDataInfo.MyMessage msg) throws Exception {
       MyDataInfo.MyMessage.DataType dataType = msg.getDataType();

       if (dataType == MyDataInfo.MyMessage.DataType.PersonType) {
           MyDataInfo.Person person = msg.getPerson();
           System.out.println(person.getName());
           System.out.println(person.getAge());
           System.out.println(person.getAddress());
       } else if (dataType == MyDataInfo.MyMessage.DataType.DogType) {
           MyDataInfo.Dog dog = msg.getDog();
           System.out.println(dog.getName());
           System.out.println(dog.getAge());
       } else if (dataType == MyDataInfo.MyMessage.DataType.CatType) {
           MyDataInfo.Cat cat = msg.getCat();

           System.out.println(cat.getName());
           System.out.println(cat.getCity());
       }
    }
}
